<?php 
namespace Users\Controller;
/**
 * 管理员管理
 * @author Haiqin
 *
 */
use Admin\Controller\AdminbaseController;
class InvitecodeadminController extends AdminbaseController{
	
	protected $m;
	
	function _initialize() {
		parent::_initialize();
		$this->m = M('UsersInvitation');
	}
	
	/**
	 * @name 邀请码列表
	 * @auth adminleft
	 */
	public function index(){
		$this->display();
	}
	
	public function edit_post(){
		if(IS_POST){
			$num = I('post.num','0');
			
			
			if($num > 0){
				for($i=0;$i<$num;$i++){
					$units[]=md5(uniqid(md5(microtime(true)),true));//生成唯一的字符串
				}
				foreach ($units as $val){
					$data = array(
						'invite_code' => $val,
						'create_time' => Date('Y-m-d H:i:s'),
						'update_time' => Date('Y-m-d H:i:s'),
					);
					$this->m->add($data);
				}
				$this->success("邀请码生成成功",U('add'));
			}else{
				$this->error("邀请码个数要大于0");
			}
		}
	}
	
	public function del(){
		$id = array_unique((array)I('ids',0));
		if ( empty($id) ) {
			$this->error('请选择要操作的数据!');
		}
		$map = array('id' => array('in', $id));
		if($this->m->where($map)->delete()){
			$this->success('删除成功',U('index'));
		} else {
			$this->error('删除失败！');
		}
	}
	
	public function changestatus(){
		$data['id'] = $_REQUEST['id'];
		$data['hasuse'] = $_REQUEST['status'];
		$data['update_time'] = date('Y-m-d H:i:s');
		if($this->m->save($data)){
			$this->success('状态更新成功');
		}else{
			$this->error('状态更新失败');
		}
	}
	
}
?>